/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bio.jpa.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Diego
 */
@Entity
@Table(name = "feature", catalog = "biodb", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Feature.findAll", query = "SELECT f FROM Feature f"),
    @NamedQuery(name = "Feature.findByIdFeature", query = "SELECT f FROM Feature f WHERE f.idFeature = :idFeature"),
    @NamedQuery(name = "Feature.findByName", query = "SELECT f FROM Feature f WHERE f.name = :name"),
    @NamedQuery(name = "Feature.findBySeq", query = "SELECT f FROM Feature f WHERE f.seq = :seq")})
public class Feature implements Serializable, Comparable<Feature> {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Basic(optional = false)
    @Column(name = "id_feature")
    private Integer idFeature;
    @Size(max = 45)
    @Column(name = "name")
    private String name;
    @Lob
    @Size(max = 16777215)
    @Column(name = "value")
    private String value;
    @Column(name = "seq")
    private Integer seq;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "featureFk")
    private List<FeatureKey> featureKeyList = new ArrayList<FeatureKey>();
    @JoinColumn(name = "gen_fk", referencedColumnName = "id_gen")
    @ManyToOne(optional = false)
    private GenBank genFk;

    public Feature() {
    }

    public Feature(String name, String value, Integer seq, GenBank genFk) {
        this.name = name;
        this.value = value;
        this.seq = seq;
        this.genFk = genFk;
    }

    public Integer getIdFeature() {
        return idFeature;
    }

    public void setIdFeature(Integer idFeature) {
        this.idFeature = idFeature;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public Integer getSeq() {
        return seq;
    }

    public void setSeq(Integer seq) {
        this.seq = seq;
    }

    @XmlTransient
    public List<FeatureKey> getFeatureKeyList() {
        return featureKeyList;
    }

    public void setFeatureKeyList(List<FeatureKey> featureKeyList) {
        this.featureKeyList = featureKeyList;
    }

    public GenBank getGenFk() {
        return genFk;
    }

    public void setGenFk(GenBank genFk) {
        this.genFk = genFk;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idFeature != null ? idFeature.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Feature)) {
            return false;
        }
        Feature other = (Feature) object;
        if ((this.idFeature == null && other.idFeature != null) || (this.idFeature != null && !this.idFeature.equals(other.idFeature))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.bio.jpa.entities.Feature[ idFeature=" + idFeature + " ]";
    }

    @Override
    public int compareTo(Feature f) {
        return getSeq().compareTo(f.getSeq());
    }
}
